package cn.lj.logistics.mapper;

import cn.lj.logistics.pojo.OrderDetail;
import cn.lj.logistics.pojo.OrderDetailExample;
import java.util.List;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;

public interface OrderDetailMapper {
    @Delete({
        "delete from t_order_detail",
        "where order_detail_id = #{orderDetailId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long orderDetailId);

    @Insert({
        "insert into t_order_detail (order_detail_id, order_id, ",
        "goods_name, goods_number, ",
        "goods_unit, goods_unit_price, ",
        "goods_total, goods_remark)",
        "values (#{orderDetailId,jdbcType=BIGINT}, #{orderId,jdbcType=BIGINT}, ",
        "#{goodsName,jdbcType=VARCHAR}, #{goodsNumber,jdbcType=INTEGER}, ",
        "#{goodsUnit,jdbcType=BIGINT}, #{goodsUnitPrice,jdbcType=DECIMAL}, ",
        "#{goodsTotal,jdbcType=DECIMAL}, #{goodsRemark,jdbcType=VARCHAR})"
    })
    int insert(OrderDetail record);

    @InsertProvider(type=OrderDetailSqlProvider.class, method="insertSelective")
    int insertSelective(OrderDetail record);

    @SelectProvider(type=OrderDetailSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="order_detail_id", property="orderDetailId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT),
        @Result(column="goods_name", property="goodsName", jdbcType=JdbcType.VARCHAR),
        @Result(column="goods_number", property="goodsNumber", jdbcType=JdbcType.INTEGER),
        @Result(column="goods_unit", property="goodsUnit", jdbcType=JdbcType.BIGINT),
        @Result(column="goods_unit_price", property="goodsUnitPrice", jdbcType=JdbcType.DECIMAL),
        @Result(column="goods_total", property="goodsTotal", jdbcType=JdbcType.DECIMAL),
        @Result(column="goods_remark", property="goodsRemark", jdbcType=JdbcType.VARCHAR)
    })
    List<OrderDetail> selectByExample(OrderDetailExample example);

    @Select({
        "select",
        "order_detail_id, order_id, goods_name, goods_number, goods_unit, goods_unit_price, ",
        "goods_total, goods_remark",
        "from t_order_detail",
        "where order_detail_id = #{orderDetailId,jdbcType=BIGINT}"
    })
    @Results({
        @Result(column="order_detail_id", property="orderDetailId", jdbcType=JdbcType.BIGINT, id=true),
        @Result(column="order_id", property="orderId", jdbcType=JdbcType.BIGINT),
        @Result(column="goods_name", property="goodsName", jdbcType=JdbcType.VARCHAR),
        @Result(column="goods_number", property="goodsNumber", jdbcType=JdbcType.INTEGER),
        @Result(column="goods_unit", property="goodsUnit", jdbcType=JdbcType.BIGINT),
        @Result(column="goods_unit_price", property="goodsUnitPrice", jdbcType=JdbcType.DECIMAL),
        @Result(column="goods_total", property="goodsTotal", jdbcType=JdbcType.DECIMAL),
        @Result(column="goods_remark", property="goodsRemark", jdbcType=JdbcType.VARCHAR)
    })
    OrderDetail selectByPrimaryKey(Long orderDetailId);

    @UpdateProvider(type=OrderDetailSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(OrderDetail record);

    @Update({
        "update t_order_detail",
        "set order_id = #{orderId,jdbcType=BIGINT},",
          "goods_name = #{goodsName,jdbcType=VARCHAR},",
          "goods_number = #{goodsNumber,jdbcType=INTEGER},",
          "goods_unit = #{goodsUnit,jdbcType=BIGINT},",
          "goods_unit_price = #{goodsUnitPrice,jdbcType=DECIMAL},",
          "goods_total = #{goodsTotal,jdbcType=DECIMAL},",
          "goods_remark = #{goodsRemark,jdbcType=VARCHAR}",
        "where order_detail_id = #{orderDetailId,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(OrderDetail record);

    /*
     * 根据订单id删除订单明细表中对应的数据
     */
    @Delete("delete from t_order_detail where order_id = #{orderId}")
	int deleteOrderDetailByOrderId(Long orderId);
}